<?php

/**
 * entity form.
 *
 * @package    worldmap
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class entityForm extends BaseentityForm
{
  protected $mapProperties = array(
    'address' => 'address',
    'lat' => 'lat',
    'lng' => 'lng'
  );

  public function configure()
  {
    unset($this['created_at']);
    unset($this['updated_at']);
    unset($this['entity_id']);
    unset($this['type']);

    $this->widgetSchema['map'] = new swWidgetFormGMapAddress();
    $defaults = array();
    $object = $this->getObject();
    foreach ($this->mapProperties as $key => $property) {
      unset($this[$key]);
      $defaults[$property] = $object[$key];
    }
    $this->setDefault('map', $defaults);
    $this->validatorSchema['map'] = new swValidatorGMapAddress();
  }

  protected function doUpdateObject($values)
  {
      if (isset($values['map'])) {
        foreach ($this->mapProperties as $key => $property) {
          if (isset($values['map'][$property])) {
            $values[$key] = $values['map'][$property];
          }
        }
        unset($values['map']);
      }
      $this->getObject()->fromArray($values);
  }
}
